/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__model_add.c                                     */
/*  NOTE      =                                                    */
/*  DATE      = 2015/01/06 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <protobuf-c/protobuf-c.h>

#include "frcomm.h"
#include "frmem.h"
#include "frame.h"
#include "client.pb-c.h"
#include "frsutl.h"
#include "frcmd_server_l7.h"
#include "frame_params.h"
#include "apmtest_cunit.h"

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

int __model_add(char *p_path,int l7_proto, char *p_l7_proto_name,int i_mem_size);

void case1(void)
{
    int i_ret = 0;
    char *p_path = frstrdup("../sqlserver/sqlserver_1.0.so");
    int l7_proto = 1433;
    char *p_l7_proto_name = frstrdup("mssql");
    int i_mem_size = 50;


    system("rm ./conf/analyzer.conf");
    system("rm ./conf/analyzer.conf_tmp3");
    i_ret = __model_add(p_path, l7_proto, p_l7_proto_name, i_mem_size);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp ./conf/analyzer.conf_tmp3 ./conf/case1.txt");

    frfree(p_path);
    frfree(p_l7_proto_name);
    return;
}

void case2(void)
{
    int i_ret = 0;
    char *p_path = frstrdup("../sqlserver/sqlserver_1.0.so");
    int l7_proto = 1433;
    char *p_l7_proto_name = frstrdup("mssql");
    int i_mem_size = 50;

    system("cp ./conf/test1.txt ./conf/analyzer.conf");
    system("rm ./conf/analyzer.conf_tmp3");
    i_ret = __model_add(p_path, l7_proto, p_l7_proto_name, i_mem_size);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp ./conf/analyzer.conf_tmp3 ./conf/test1_case2.txt");

    frfree(p_path);
    frfree(p_l7_proto_name);
    return;
}

void case3(void)
{
    int i_ret = 0;
    char *p_path = frstrdup("../sqlserver/sqlserver_1.0.so");
    int l7_proto = 1433;
    char *p_l7_proto_name = frstrdup("mssql");
    int i_mem_size = 50;

    system("rm ./conf/analyzer.conf");
    system("cp ./conf/test1.txt ./conf/analyzer.conf_tmp3");
    i_ret = __model_add(p_path, l7_proto, p_l7_proto_name, i_mem_size);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp ./conf/analyzer.conf_tmp3 ./conf/test1_case3.txt");

    frfree(p_path);
    frfree(p_l7_proto_name);
    return;
}

void case4(void)
{
    int i_ret = 0;
    char *p_path = frstrdup("../sqlserver/sqlserver_1.0.so");
    int l7_proto = 1433;
    char *p_l7_proto_name = frstrdup("mssql");
    int i_mem_size = 50;

    system("rm ./conf/analyzer.conf");
    system("cp ./conf/test2.txt ./conf/analyzer.conf_tmp3");
    i_ret = __model_add(p_path, l7_proto, p_l7_proto_name, i_mem_size);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp ./conf/analyzer.conf_tmp3 ./conf/test2_case4.txt");

    frfree(p_path);
    frfree(p_l7_proto_name);
    return;
}

void case5(void)
{
    int i_ret = 0;
    char *p_path = frstrdup("../sqlserver/sqlserver_1.0.so");
    int l7_proto = 1433;
    char *p_l7_proto_name = frstrdup("mssql");
    int i_mem_size = 50;

    system("rm ./conf/analyzer.conf");
    system("cp ./conf/test3.txt ./conf/analyzer.conf_tmp3");
    i_ret = __model_add(p_path, l7_proto, p_l7_proto_name, i_mem_size);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp ./conf/analyzer.conf_tmp3 ./conf/test3_case5.txt");

    frfree(p_path);
    frfree(p_l7_proto_name);
    return;
}

int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t__model_add 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);
    CU_add_test(pSuite, "case2", case2);
    CU_add_test(pSuite, "case3", case3);
    CU_add_test(pSuite, "case4", case4);
    CU_add_test(pSuite, "case5", case5);
  //  CU_add_test(pSuite, "case6", case6);
//    CU_add_test(pSuite, "case7", case7);
//    CU_add_test(pSuite, "case8", case8);

    return 0;

}

int main(int argc, char **argv)
{
    frmem_init();
    run_cunit(add_suite);
    frshow_leak();
    frmem_destroy();
    return 0;
}

